iT邦幫忙

2024 iThome 鐵人賽

DAY 28
0
佛心分享-我的私藏工具箱

正則!好好表達系列 第 28

用Perl產出過版清單貼上Excel

  • 分享至 

  • xImage
  •  

在DAY 25裡是將弱掃報告清單透過Regex轉成CSV格式以便貼上Excel。今天情況相同,客戶要求提供一份Excel過版清單,記錄路徑及名稱,所以用Perl:

#!/usr/bin/perl
use File::Find qw(finddepth);

my $fcb = "/Users/jemmy/Downloads/SpringBootTutorial-Ch18-1/src";

finddepth(sub {
    my $fname = $File::Find::name;
    my @ary = split/\t/;
    return if ($ary[-1] =~ /^[.].*/);  # 遇.及..跳過
    my $dir = "MyProject/" . substr($fname, length($fcb) + 1, length($fname) - length($fcb) - 2 - length($ary[-1]));
    my @tst = split(".", $ary[-1]);
    print "2024/10/11\tMyProject\tPROD\t9527\t$dir\t$ary[-1]\n" unless (-d $fname);

}, $fcb);

前四個欄位為固定內容,包括過版日期、專案名、環境、issue單號,後面兩個欄位則是遞迴讀檔案清單:路徑及檔名。
得到內容如下,然後複製貼上Excel

2024/10/11	MyProject	PROD	9527	MyProject/main/resources	application.properties
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo	DemoController.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo	SecurityConfig.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo	Application.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo	UserRepository.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo/model	AppUser.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo/model	LoginRequest.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo/model	UserAuthority.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo/model	LoginResponse.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo/service	TokenService.java
2024/10/11	MyProject	PROD	9527	MyProject/main/java/com/vincent/demo/service	UserDetailsServiceImpl.java

上一篇
Spring Boot的RequestBody檢核
下一篇
如何給Select出來的記錄加編號,以便分批Select
系列文
正則!好好表達30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言